using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PSE.Hosting.Management.Windows
{
    public partial class AddPackageForm : Form
    {
        private string _packageName;

        public string PackageName
        {
            get { return _packageName; }
        }

        private string _domain;

        public string Domain
        {
            get { return _domain; }
        }

        private string _userName;

        public string UserName
        {
            get { return _userName; }
        }

        private string _password;

        public string Password
        {
            get { return _password; }
        }

        public AddPackageForm()
        {
            InitializeComponent();
        }

        public AddPackageForm(string packageName, string domain, string userName)
            : this()
        {
            if (!string.IsNullOrEmpty(packageName))
            {
                txtPackageName.ReadOnly = true;
                txtPackageName.Text = packageName;

                txtDomain.Text = domain;
                txtUserName.Text = userName;

                this.Text = "Update Package";
            }
        }

        private void cmdOk_Click(object sender, EventArgs e)
        {
            if (Business.ValidatePackageName(txtPackageName.Text))
            {
                _packageName = txtPackageName.Text;
                _domain = txtDomain.Text;
                _userName = txtUserName.Text;
                _password = txtPassword.Text;

                this.DialogResult = DialogResult.OK;
                this.Hide();
            }
            else
            {
                MessageBox.Show("Invalid package name.", "Service Hoster", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void AddPackageForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                this.Close();
        }
    }
}